﻿@model CNRegex.Entity.RegexExpression
@{
	Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2 class="regexCreateH2">
	@ViewBag.Title
</h2>
<style type="text/css">
	.btnCode
	{
		background: transparent url(/images/code.gif) no-repeat 16px 16px;
		background-position: 2px 2px;
	}
</style>
<script src="@Url.Content("~/Scripts/kindeditor/kindeditor-min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/common.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/css/RegexCreate.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	$(document).ready(
		function () {
			registerKindeditor("Description",null,1);
		}
	);

	function validation() {
		var expName = jQuery.trim($("#Title").val());
		var expCategory = $("#CategoryID").val();
		var exp = $("#Expression").val();
		var expMatch = jQuery.trim($("#txtMatch0").val() + $("#txtMatch1").val() + $("#txtMatch2").val());
		var expNoMatch = jQuery.trim($("#txtNonMatch0").val() + $("#txtNonMatch1").val() + $("#txtNonMatch2").val());
		var isValide = true;
		if (expName == "") {
			$("#spanExpName").fadeIn().css("display", "block");
			isValide = false;
		} else {
			$("#spanExpName").fadeOut();
		}
		if (expCategory == "") {
			$("#spanExpCategory").fadeIn().css("display", "block");
			isValide = false;
		} else {
			$("#spanExpCategory").fadeOut();
		}

		if (exp == "") {
			$("#spanExp").fadeIn().css("display", "block");
			isValide = false;
		} else {
			$("#spanExp").fadeOut();
		}
		if (expMatch == "") {
			$("#spanExpMatch").fadeIn().css("display", "inline");
			$("#spanErrorMatch").fadeIn().css("display", "block");
			isValide = false;
		} else {
			$("#spanExpMatch").fadeOut();
			$("#spanErrorMatch").fadeOut();
		}
		if (expNoMatch == "") {
			$("#spanExpNonMatch").fadeIn().css("display", "inline");
			$("#spanErrorNonMatch").fadeIn().css("display", "block");
			isValide = false;
		} else {
			$("#spanExpNonMatch").fadeOut();
			$("#spanErrorNonMatch").fadeOut();
		}
		return isValide;
	}
</script>
@using (Html.BeginForm())
{
	@Html.HiddenFor(model => model.ID)
	<div style="">
		<ul class="regexCreateErrorUl">
			<li class="displayNone" id="spanExpCategory" style="list-style-type:square;">○请选择表达式的分类</li>
			<li class="displayNone" id="spanExp">○请填写表达式的内容</li>
			<li class="displayNone" id="spanExpName">○请输入表达式的名称</li>
			<li class="displayNone" id="spanErrorMatch">○请输入至少1个匹配示例</li>
			<li class="displayNone" id="spanErrorNonMatch">○请输入至少1个非匹配示例</li>
		</ul>
	</div>
	<table class="regexCreateTable">
		<colgroup>
			<col width="46%" />
			<col />
		</colgroup>
		<tr>
			<td>
				<div class="regexCreate_editor_label">
					@Html.LabelFor(model => model.Title, "表达式名称")
				</div>
				<div>
					@Html.EditorFor(model => model.Title)
					<span class="required" id="nameRequired">* </span>
				</div>
			</td>
			<td>
				<div class="regexCreate_editor_label">
					@Html.LabelFor(model => model.CategoryID, "表达式分类")
				</div>
				<div>
					@Html.DropDownList("CategoryID")
					<span class="required">* </span>
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<div class="regexCreate_editor_label">
					@Html.LabelFor(model => model.Expression, "表达式内容")
				</div>
				<div>
					@Html.TextAreaFor(model => model.Expression, new { @class = "textarea-style1" })
					<span class="required">* </span>
				</div>
			</td>
			<td>
				<div class="regexCreate_editor_label">
					@Html.LabelFor(model => model.Description, "描述")
				</div>
				<div>
					@Html.TextAreaFor(model => model.Description, new {style="height:105px;"})
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<div class="regexCreate_editor_label">
					<span style="background: url(/images/greencheck.gif) no-repeat; width: 20px; height: 20px;
						float: left;"></span>
					@Html.LabelFor(model => model.Matches, "匹配的示例")
					<span class="tip1" style="margin-left: 32px;" id="spanExpMatch">请输入至少1个<span style="color: green;
						font-size: 14px; margin: 0px 2px; font-weight: bold;">匹配</span>的文本示例. 例如a@a.com
					</span><span class="required">* </span>
				</div>
				@{
string[] matches = new string[0];
if (Model != null)
{
	matches = Model.Matches.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
}
				}
				<div class="editor-field">
					<ul class="regexCreateMatch">
						<li>1.<input id="txtMatch0" name="match" value='@(matches.Length > 0 ? matches[0] : "")' /></li>
						<li>2.<input id="txtMatch1" name="match" value='@(matches.Length > 1 ? matches[1] : "")' /></li>
						<li>3.<input id="txtMatch2" name="match" value='@(matches.Length > 2 ? matches[2] : "")' /></li>
					</ul>
				</div>
			</td>
			<td>
				<div class="regexCreate_editor_label">
					<span style="background: url(/images/cross.png) no-repeat; width: 20px; height: 20px;
						float: left;"></span>
					@Html.LabelFor(model => model.NonMatches, "不匹配的示例")
					<span class="tip1" id="spanExpNonMatch">请输入至少1个<span style="color: Red; font-size: 14px;
						margin: 0px 2px; font-weight: bold;">不匹配</span>的文本示例. 例如@@word </span><span class="required">
							* </span>
				</div>
				@{
string[] nonMatches = new string[0];
if (Model != null)
{
	nonMatches = Model.NonMatches.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
}
				}
				<div class="editor-field">
					<ul class="regexCreateMatch">
						<li>1.<input id="txtNonMatch0" name="NonMatch" value='@(nonMatches.Length > 0 ? nonMatches[0] : "")' /></li>
						<li>2.<input id="txtNonMatch1" name="NonMatch" value='@(nonMatches.Length > 1 ? nonMatches[1] : "")' /></li>
						<li>3.<input id="txtNonMatch2" name="NonMatch" value='@(nonMatches.Length > 2 ? nonMatches[2] : "")' /></li>
					</ul>
				</div>
			</td>
		</tr>
	</table>
	<p>
		<input type="submit" value="确定" onclick="return validation();" />
	</p>
}
